/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __MC2_TILING_UTILS_INTERFACE_H__
#define __MC2_TILING_UTILS_INTERFACE_H__

#include "hccl/base.h"
#include "kernel_tiling/kernel_tiling.h"

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

inline uint32_t MC2TilingGetVer(void *tiling) {
    return *(uint32_t *)tiling;
}

inline uint32_t MC2TilingGetHcommCnt(void *tiling) {
    return *(uint32_t *)((uint8_t *)tiling + sizeof(uint32_t));
}

inline Mc2HcommCfg *MC2TilingGetHcommCfg(void *tiling, uint32_t idx) {
    uint32_t cnt = MC2TilingGetHcommCnt(tiling);
    if (idx >= cnt) {
        return nullptr;
    }
    return (Mc2HcommCfg *)((uint8_t *)tiling + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(Mc2ServerCfg) + idx * sizeof(Mc2HcommCfg));
}

inline Mc2ServerCfg *MC2TilingGetServerCfg(void *tiling) {
    return (Mc2ServerCfg *)((uint8_t *)tiling + sizeof(uint32_t) + sizeof(uint32_t));
}

#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __MC2_TILING_UTILS_INTERFACE_H__